from django.db import models


# Create your models here.
# 物种表
class SpeciesModel(models.Model):
    species = models.CharField(max_length=20, verbose_name='物种名称', null=False, blank=False)

    class Meta:
        db_table = 'species'
        verbose_name = '物种表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.species


# FoodModel model definition
# 食谱表
class FoodModel(models.Model):
    food = models.CharField(max_length=20, verbose_name='食物名称', null=False, blank=False)
    type = models.CharField(max_length=50, verbose_name='食物分类', null=False, blank=False)
    grade = models.IntegerField(choices=[
        (1, '不能吃'),
        (2, '慎吃'),
        (3, '可吃')
    ], verbose_name='食用等级', null=False, blank=False)
    image = models.ImageField(upload_to='food_images/', verbose_name='食谱图片', null=True, blank=True)
    species_id = models.ForeignKey(SpeciesModel, on_delete=models.CASCADE, verbose_name='物种关联',
                                   related_name='foods')

    class Meta:
        db_table = 'food'
        verbose_name = '食物表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.food

# 宠物年龄
class PetAgeModel(models.Model):
    age = models.CharField(max_length=20, verbose_name='年龄')
    species = models.ForeignKey(SpeciesModel, on_delete=models.CASCADE, verbose_name='物种关联', related_name='ages')

    def __str__(self):
        return self.age

    class Meta:
        db_table = 'petage'
        verbose_name = '宠物年龄'
        verbose_name_plural = verbose_name

#活动表
class ActivityModel(models.Model):
    activity = models.CharField(max_length=20, verbose_name='活动')
    type = models.CharField(max_length=50, verbose_name='活动分类')
    grade = models.IntegerField(choices=((1, '不能做'), (2, '慎做'), (3, '可做')), verbose_name='活动等级')
    image = models.ImageField(upload_to='activity_images/', null=True, blank=True, verbose_name='活动图片')
    pet_ages = models.ManyToManyField(PetAgeModel, verbose_name='宠物年龄')

    def __str__(self):
        return self.activity

    class Meta:
        db_table = 'activity'
        verbose_name = '活动'
        verbose_name_plural = verbose_name
#宠物百科
class PetEncyclopediaModel(models.Model):
    title = models.CharField(max_length=50, verbose_name="文章名称", null=False, blank=False)
    type = models.IntegerField(choices=(
        ('1', '养育百科'),
        ('2', '喂食百科')
    ), verbose_name="文章类型", null=False, blank=False)
    content = models.TextField(verbose_name="文章内容", null=False, blank=False)
    images = models.ImageField(upload_to='pet_encyclopedia/', verbose_name="文章图片", null=True, blank=False)
    collect = models.IntegerField(default=0, verbose_name="收藏量", null=False, blank=False)
    read = models.IntegerField(default=0, verbose_name="阅读量", null=False, blank=False)

    class Meta:
        db_table = 'encyclopedia'
        verbose_name = "宠物百科"
        verbose_name_plural = "宠物百科列表"

    def __str__(self):
        return self.title
